package cn.edu.stu.syllabus.utils;

import android.net.Uri;
import android.os.Build;
import android.support.v4.content.FileProvider;

import java.io.File;

import cn.edu.stu.syllabus.application.SyllabusApplication;

/**
 * Created by daidaijie on 2017/3/23.
 * 适配Android N以上的File Uri获取
 */

public class Android_N_Utils {

    /**
     * 将File对象转化为对应的Uri地址
     * @param file File对象
     * @return 转化后的地址
     */
    public static Uri getFileUri(File file) {
        Uri uri;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            uri = FileProvider.getUriForFile(SyllabusApplication.getContext(),
                    "cn.edu.stu.syllabus.fileprovider", file);
        } else {
            uri = Uri.fromFile(file);
        }
        return uri;
    }
}
